package com.vladimirjosu.backgammon;

import java.util.Random;

import android.content.Context;
import android.content.res.Resources;
import android.widget.ImageView;

public class Dice extends ImageView {
	private static final Random mRandom = new Random();
	private static final int MAX_VALUE = 6;
	private static final int INVALID_VALUE = 0;
	private int mValue;
	private boolean mValid;
	private Resources mResources;

	public Dice(Context context) {
		super(context);
		mValid = false;
		mResources = context.getResources();
	}
	public void roll() {
		mValue = mRandom.nextInt(MAX_VALUE) + 1;
		mValid = true;
		switch (mValue) {
		case 1:
			setImageDrawable(mResources.getDrawable(R.drawable.dice1));
			break;
		case 2:
			setImageDrawable(mResources.getDrawable(R.drawable.dice2));
			break;
		case 3:
			setImageDrawable(mResources.getDrawable(R.drawable.dice3));
			break;
		case 4:
			setImageDrawable(mResources.getDrawable(R.drawable.dice4));
			break;
		case 5:
			setImageDrawable(mResources.getDrawable(R.drawable.dice5));
			break;
		case 6:
			setImageDrawable(mResources.getDrawable(R.drawable.dice6));
			break;
		default:
			setImageDrawable(mResources.getDrawable(R.drawable.dice1));
			break;
		}
	}
	public boolean isValid() {
		return mValid;
	}
	public int getValue() {
		if (isValid()) {
			return mValue;
		} else {
			return INVALID_VALUE;
		}
	}
}
